package main

import (
	"fmt"
	"strings"
)

// 案例：统计一个字符串中单词出现的次数

func main() {

	var s string = "how do you do sds sds hahah hahha dsssdd do do do"
	// 1. 定义一个map[string]int
	var wordCount = make(map[string]int, 10)
	// 2. 解析字符串中单词
	words := strings.Split(s, " ")
	// 3. 遍历单词进行统计操作
	for _, word := range words {
		_, ok := wordCount[word]
		if ok {
			wordCount[word]++
		} else {
			wordCount[word] = 1
		}
	}

	fmt.Println(wordCount)
}
